package com.zhang.common.util.result;

import java.util.Map;

public class RUtils {
    private RUtils() {
    }

    /**
     * 返回结果是枚举
     *
     * @param rEnum r枚举
     * @return {@link R}
     */
    public static R resultEnum(REnum rEnum) {
        R r = new R();
        r.setCode(rEnum.getCode());
        r.setMsg(rEnum.getMsg());
        return r;
    }

    /*
     * 成功，有返回结果*/
    public static R successData(Object object) {
        R r = new R();
        r.setCode(REnum.SUCCESS.getCode());
        r.setMsg(REnum.SUCCESS.getMsg());
        r.setData(object);
        return r;
    }

    public static R successDataMsg(Object object, String msg) {
        R r = new R();
        r.setCode(REnum.SUCCESS.getCode());
        r.setMsg(msg);
        r.setData(object);
        return r;
    }

    public static R successMsg(String msg) {
        R r = new R();
        r.setCode(REnum.SUCCESS.getCode());
        r.setMsg(msg);
        return r;
    }

    //成功，但返回体没数据
    public static R success() {
        return successData(null);
    }

    //失败返回信息,s手动返回状态码
    public static R err(Integer code, String msg) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    /**
     * 错误返回结果，默认状态码为500
     *
     * @param msg 味精
     * @return {@link R}
     */
    public static R err(String msg) {
        R r = new R();
        r.setCode(REnum.UNAUTHORIZED.getCode());
        r.setMsg(msg);
        return r;
    }

    /**
     * 直接返回默认错误
     *
     * @return {@link R}
     */
    public static R err() {
        R r = new R();
        r.setCode(REnum.UNKNOWN_ERROR.getCode());
        r.setMsg(REnum.UNKNOWN_ERROR.getMsg());
        return r;
    }


}
